package cm.tl.pms.webservice;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Auther: lwp
 * @Date: 2022/11/16 - 11 - 16 - 13:52
 * @Description
 * @version: 1.0
 */
@Configuration
public class MybatisPlusConfig {


    /**
     * 防止 修改与删除时对全表进行操作
     *
     * @return
     */
    @Bean
    public BlockAttackInnerInterceptor blockAttackInnerInterceptor() {
        return new BlockAttackInnerInterceptor();
    }


    /**
     * 新的分页插件,一缓和二缓遵循mybatis的规则,需要设置 MybatisConfiguration#useDeprecatedExecutor = false 避免缓存出现问题
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        // 创建分页拦截器
        // PaginationInnerInterceptor paginationInterceptor = new PaginationInnerInterceptor();
        // // 设置每页最大条数
        // paginationInterceptor.setMaxLimit(1000L);
        // // 添加分页拦截器到MyBatis Plus拦截器链
        // interceptor.addInnerInterceptor(paginationInterceptor);

        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }

}
